package com.hanbang.mrcm.aboutme;

import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;
import com.hanbang.mrcm.R;
import com.hanbang.mrcm.base.BaseActivity;
import com.hanbang.mrcm.utils.HttpInterfaces;
import com.hanbang.mrcm.utils.MyRequestCallBack;
import com.hanbang.mrcm.utils.MyToast;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

public class FeedbackActivity extends BaseActivity {

	private EditText editText = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.feedback);
		initView();
		setOnClickListener();
	}

	/*
	 * 设置点击事件
	 */
	private void setOnClickListener() {
		findViewById(R.id.ok).setOnClickListener(onClickListener);

	}

	private OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.ok:
				commit(editText.getText().toString().trim());
				break;

			default:
				break;
			}
		}
	};

	private void commit(String content) {
		if (!isLogin(true)) {
			return;
		}
		if (content == null || content.isEmpty()) {
			MyToast.show(this, "请写下您要说的话", Toast.LENGTH_SHORT);
			return;
		}
		httpUtils.send(HttpMethod.GET, HttpInterfaces.commentAdd + "&mobile="
				+ userData.getMobile() + "&password=" + userData.getPassword()
				+ "&txtContent=" + content, new MyRequestCallBack<String>(this,
				getString(R.string.loadding)) {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				super.onSuccess(responseInfo);
				try {
					JSONObject json = new JSONObject(responseInfo.result);
					int status = json.getInt("status");
					if (status == 1) {
						MyToast.show(FeedbackActivity.this,
								json.getString("msg"), Toast.LENGTH_SHORT);
						editText.setText("");
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
		});

	}

	/*
	 * 初始化view
	 */
	private void initView() {
		// 设置顶部的标题
		setBackArrows(findViewById(R.id.top_bar_left_image));
		setTitle(findViewById(R.id.top_bar_title), "意见反馈");
		editText = (EditText) findViewById(R.id.edittext);

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}
}
